Skip to main content

Placeholders with Format Definition

The output text of an element can display the value of a variable by means of a placeholder (%) with a format definition. When the text is displayed, the value of the variable is inserted instead of the placeholder. The data type in the format definition and of the variable have to be identical.

The displayed string is listed in the Text element property. The variable is listed in the Text variable property.

Visualization users can specify a text in an element, in which the text, for example, is stored and displayed as a text output variable. The user input has to correspond to the input format. The data type of the text output variable has to correspond to the data type which is defined for the input format.

The format definition for the input text is located in the Input configuration dialog, in Text input, in the Write Variable input action. The variable is listed in the Text variable property.

Integer

The format definition for an integer has the following format:

% <flags> <minimum number of digits> <type>

Recommended data types: BYTE | WORD | DWORD | LWORD | SINT | USINT | INT | UINT | DINT | UDINT | LINT | ULINT

Syntax

Example

Description

Example in Visualization

<flags>

Optional and combinable

Code: iValue : INT := -12;

Text variable property: PLC_PRG.iCounter

-

%-5d

Alignment left-justified, with respect to the minimum width of the number (specified in minimum number of digits)

Text property: Value: %-5d

+

%+d

Output always with a sign

Text property: Value: %+d

Output: Value: -12

0

%05d

Places are filled with a 0 until the minimum number of places (including the sign) is reached

Text property: Value: %05d

<minimum number of digits>

%5d

Optional

Minimum number of places

Syntax

Example

Description

Example in Visualization

<type>

Required

d

i

%d

Output as an integer decimal number

Code: iValue : INT := -12;

Text property: Value: %d

Text variable property: PLC_PRG.iCounter

Output: Value: -12

%+05d

Code: iValue : INT := -12;

Text property: Value: %+05d

Text variable property: PLC_PRG.iCounter

Output: Value: -0012

b

%08b

Output as unsigned, integer binary number without a prefix

Code: byCode : BYTE := 255;

Text property: Coding: %08b

Text variable property: PLC_PRG.byCode

Output: Coding: 11111111

o

%04o

Output as unsigned, integer octal number without a prefix

Code: byCode : BYTE := 8#377;

Text property: Octal number: %04o

Text variable property: PLC_PRG.byCode

Output: Octal number: 0377

x

%04x

Output as an unsigned 32-bit hexadecimal number with the digits a–f (lowercase) without a prefix and without a separator

Code: wCode : WORD := 16#1;

Text property: Coding: 16#%04x

Text variable property: PLC_PRG.dwCode

Output: Coding: 16#0001

X

%08X

Output as an unsigned 32-bit hexadecimal number with the digits A–F (uppercase) without a prefix and without a separator

Code: dwCode : DWORD := 16#FFFFFFFF;

Text property: Coding: %08X

Text variable property: PLC_PRG.dwCode

Output: Coding: FFFFFFFF

llx

%016llx

Output as an unsigned 64-bit hexadecimal number with the digits a–f (lowercase) without a prefix and without a separator

Note: llx means "long long hexadecimal"

Recommended data types: LWORD | LINT | ULINT

Code: lwCode : LWORD := 16#4FFF_3FFF_2FFF_1FFF;

Text property: Coding: 16#%016llx

Text variable property: PLC_PRG.lwCode

Output: Coding: 16#4fff3fff2fff1fff

llX

%016llX

Output as an unsigned 64-bit hexadecimal number with the digits A–F (uppercase) without a prefix and without a separator

Recommended data types: LWORD | LINT | ULINT

Code: lwCode : LWORD := 16#4FFF_3FFF_2FFF_1FFF;

Text property: Coding: %016llX

Text variable property: PLC_PRG.lwCode

Output: Coding: 4FFF3FFF2FFF1FFF

u

%5u

Output as an unsigned integer decimal number

Recommended data types: USINT | UINT | UDINT | ULINT

Code: uiNumber : UINT := 1234;

Text property: Number: %u

Text variable property: PLC_PRG.uiNumber

Output: Number: 1234

Floating-point number in fixed-point notation

Floating-point numbers can be displayed as a decimal number in fixed-point notation. The format definition for this has the following format:

% <flags> <minimum number of digits> . <accuracy> f

Recommended data types for this kind of placeholder variable: REAL | LREAL

Syntax

Example

Description

Example in Visualization

<flags>

Optional and combinable

-

%-12.9f

Alignment left-justified, with respect to the minimum number of digits

+

%+f

Always with a sign, also for positive numbers

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %+f

Text variable property: PLC_PRG.lrVar

Output: lrVar: +0.001235

0

%012.3f

Places are filled with a 0 until the minimum number of places (including the sign and decimal point) is reached

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %012.3f

Text variable property: PLC_PRG.lrVar

Output: lrVar: 00000000.001

<minimum number of digits> . <accuracy>

Optional

When not specified, the number is output in standard format 1.6

<minimum number of digits>

%012.3f

Minimum number of places including the sign and decimal point

Example: 12

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %012.3f

Text variable property: PLC_PRG.lrVar

Output: lrVar: 000000000000.001

<accuracy>

%1.3f

Accuracy in places and the decimal point

Example: 3

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %1.3f

Text variable property: PLC_PRG.lrVar

Output: lrVar: 0.001

f

%f

Required

Format identifier for decimal display with the decimal point

Code: rWeight : REAL := 0.123456789;

Text property: Weight: %f

Text variable property: PLC_PRG.rWeight

Output: rWeight: 1.234568

Floating-point number in exponential notation

Floating-point numbers can be displayed in standardized exponential notation with base 10. The format definition for exponential notation has the following format:

% <flags> <minimum number of digits> . <accuracy> <type>

Recommended data types for this kind of placeholder variable: REAL | LREAL

Syntax

Example

Description

Example in Visualization

<flags>

Optional and combinable

-

%-12.3e

Alignment left-justified, with respect to the minimum number of digits

+

%+e

Always with a sign, also for positive numbers

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %+e

Text variable property: PLC_PRG.lrVar

Output: lrVar: +1.234567e-003

0

%012.9e

Places are filled with a 0 until the minimum number of places (including the sign and decimal point) is reached

Code: lrVar : LREAL := -1.234567E-003;

Text property: : %012.3f

Text variable property: PLC_PRG.lrVar

Output: lrVar: -01.234e-003

<minimum number of digits> . <accuracy>

Optional

When not specified, the mantissa is output in standard format 1.6

<minimum number of digits>

%12.3e

Minimum number of places, including the sign (for mantissa and exponent), decimal point, and exponents ( E, e)

Example: 12

Code: lrVar : LREAL := 1.234567E-003;

Text property: lrVar: %e

Text variable property: PLC_PRG.lrVar

Output: lrVar: 1.234567.-003

<accuracy>

%12.3e

Accuracy of the mantissa in places and the decimal point

Example: 3

Code: lrVar : LREAL := -1.234567E-003;

Text property: %012.3e

Text variable property: PLC_PRG.lrVar

Output: lrVar: -01.235e-003

<type>

Required

e

%e

Display with e

Code: rValue : REAL := 0.009876543210;

Text property: rValue: %e

Text variable property: PLC_PRG.rValue

Output: rValue: 9.876544e-003

E

%E

Display with E

Code: rValue : REAL := 0.009876543210;

Text property: rValue: %E

Text variable property: PLC_PRG.rValue

Output: rValue: 9.876544E-003

Time in integers

Compatibility Notice

In order to get the usual display, in V3.5 SP17 and higher, as a rule three digits are used for the output of fractions of a second (ms/µs/ns). Example: In %t[dd-HH:mm:ss:ms], ms is specified with three digits for the milliseconds. For this purpose, the two-digit ms number is prepended with a zero.If a two-digit output is desired (like before V3.5 SP17), then a special compiler define has to be set in the compiler properties of the application: VISU_MILLISEC_NOLEADING_ZERO.

If the output text in the Text element property contains the placeholder %t with an identification for a time unit, then a time, a time duration, or a time interval is output. The placeholder variable is assigned in the Text variable property.

The placeholder for a time per time unit has the following format:

%t[ <text> <time in unit> <text> ]

Recommended data types: TIME, LTIME

Syntax

Example

Description

Example in Visualization

<time in unit>

Required

Identification for a time unit

Filters from the time value the complete number of the specified time unit (days, hours, minutes, seconds, milliseconds)

For 64-bit time values, also microseconds and nanoseconds

Valid for the following examples:

Code: ltTimeSpan : LTIME := LTIME#1D2H3M4S5MS6US7NS;;

Text variable property: PLC_PRG.ltTimeSpan

d

%t[d]

Number of days, without a prepended zero

Text property: Time span: %t[d] d

Output: Time span: 1 d

dd

%t[dd]

Number of whole days, with a prepended zero

Text property: Time span: %t[dd] days

Output: Time span: 01 days

H

%t[H]

Number of hours (0–23)

Text property: Time span: %t[H] h

Output: Time span: 2 h

HH

%t[HH]

Number of hours (00–23)

Text property: Time span: %t[HH] h

Output: Time span: 02 h

h

%t[h]

Number of hours (0–23)

Text property: Time span: %t[h] h

Output: Time span: 2 h

hh

%t[hh]

Number of hours (00–23)

Text property: Time span: %t[h] h

Output: Time span: 02 h

m

%t[m]

Number of minutes (0–59), without leading zero

Text property: Time span: %t[m] m

Output: Time span: 3 m

mm

%t[mm]

Number of minutes (00–59), with leading zero

Text property: Period: %t[mm] m

Output: Time span: 03 m

s

%t[s]

Number of seconds (00–59), without leading zero

Text property: Time span: %t[s] s

Output: Time span: 4 s

ss

%t[ss]

Number of seconds (00–59), with leading zero

Text property: Time span: %t[ss] s

Output: Time span: 04 s

ms

%t[ms]

Number of fractional seconds, in milliseconds (0–999)

Text property: Time span: %t[ms] ms

Output: Time span: 005 ms

us

%t[us]

Number of fractional seconds, in microseconds (0–999)

Only for data type LTIME

Text property: Time span: %t[us] µs

Output: Time span: 006 µs

Note: Overflow is permitted in the greatest time unit of a definition.

ns

%t[ns]

Number of fractional seconds, in nanoseconds (0–999)

Only for data type LTIME

Text property: Time span: %t[ns] ns

Output: Time span: 007 ns

Note: Overflow is permitted in the greatest time unit of a definition.

<text>

%t[ns nanoseconds]

%t[ns 'ns']

Optional

Strings, which are specified inside brackets, are included in the output

Note: If a string should be output, which corresponds to an identification for a time unit or which contains identifications for time units, then the string has to be enclosed in single straight quotation marks.

Text property: %t[Time span: ns nanoseconds]

Output: Time span: 007 nanoseconds

Text property: %t[Time span: ns 'ns']

Output: Time span: 007 ns

Inside the brackets, identifications for time units can occur any number of times and can be interchanged with any strings.

Syntax

Example

Description

Example in Visualization

%t[dd-HH.m.s.ms.us.ns]

Time format for all time units, with the usual separator in between

Text property: Value: %t[dd-HH:mm:ss:ms:us:ns]

Output: Value: 01-02:03:04:005:006:007

%t['Time span:' dd-HH:mm:ss:ms:us:ns]

Format with additional strings which should be output, without considering the identifications for time units

These kinds of strings are enclosed in simple straight quotation marks.

Text property: Time span %t[dd-HH:mm:ss:ms:us:ns]

Output: Time span: 01-02:03:04:005:006:007

Time as decimal number

Recommended data types: TIME, LTIME

In the format definition, the time duration <time in unit> can be identified with the decimal place identification <number of decimal places>. The result is that the time duration is formatted as a decimal number (with decimal places) in the specified time unit. That is possible for the following time formats: HH | H | hh | h| mm | m | ss | s | ms |us | ns. This can be useful for user input.

The placeholder for a time span as a decimal number has the following format:

%t[ <time in unit> <number of decimal places>]

Syntax

Example

Description

Example in Visualization

<time in unit>

Required

Identification of a time unit which formats the time value in the specified time unit (days, hours, minutes, seconds, milliseconds) as a decimal number

For 64-bit time values, also microseconds and nanoseconds

<number of decimal places>

Required

Maximum number of decimal places (>=0) which are displayed or entered

Note: Even if decimal places are not desired for the input or display, at least the number 0 has to be specified to allow for fractional input.

The requirements apply for the following examples:

Code: ltTime : LTIME;

Text variable property: PLC_PRG.ltTime

HH

H

hh

h

%t[hh4]

%t[h4]

Time value (in hours) as a decimal number

Number of hours (0–23)

Example: 4

Text property: %t[hh2]

User input: 1.25

Time value: ltTime = T#1h15m

mm

m

%t[mm2]

%t[m2]

Time value (in minutes) as a decimal number

Example: 2

User input: 1.25

Time value ltTime = T#1M15S

ss

s

%t[ss3]

Time value (in seconds) as a decimal number

Example: 3

User input: 1.25

Time value ltTime = T#1S250MS

%t[ss0]

Example: 0

User input: 1000

Time value ltTime = T#16M40S

ms

%t[ms3]

Time value (in milliseconds) as a decimal number

Example: 3

User input: 1.25

Time value ltTime = T#1MS250MS

us

%t[us3]

Time value (in microseconds) as a decimal number

Example: 3

User input: 1.25

Time value ltTime = T#1US250NS

ns

%t[ns0]

Time value (in nanoseconds) as a decimal number

Example: 0

User input: 125

Time value ltTime = T#125NS

System time

If a variable is not assigned to a placeholder with a format definition, then the system time is output.

Syntax

Example

Description

Example in Visualization

t

%t[HH:mm:ss:ms]

Output of the current system time

Requirement: No variable is specified below the Text variable property.

Text property: Time: %t[HH:mm:ss:ms]

Text variable property: blank

Output: Time: 8:59:59 AM:999

Z

%t[dd:MM:yyyy HH:mm:ss:ms:Z]

Optional

Output of the offset of the local system time as universal time (UTC)

Text property: Time: %t[dd:MM:yyyy HH:mm:ss:ms:Z]

Depending on the UTC variable VisuElems.Visu_DateTime.DisplayUTC, the following is displayed:

  • TRUE -> Time: 08/01/2021 04:59:59:999:Z

  • FALSE -> Time: 08/01/2021 06:59:59:999:+02:00

Tip

You can programmatically switch the local time zone of the system time to universal time (UTC).

When the variable VisuElems.Visu_DateTime.DisplayUTC is set to TRUE, the system time is displayed as universal time (UTC). By default, the variable VisuElems.Visu_DateTime.DisplayUTC is set to FALSE so that the system time is displayed in the local time zone.

For the display of date and time values, you can extend the respective format string with the time zone code Z. For an output in local system time, the offset is then displayed in universal time (UTC). For example, dd:MM:yyyy HH:mm:ss:ms:Z outputs 01.08.2021 12:00:00:001:+02:00. When universal time (UTC) is displayed, the UTC code is also displayed. 01.08.2021 10:00:00:001:Z

Date and time

Compatibility Notice

In order to get the usual display, in V3.5 SP17 and higher, as a rule three digits are used for the output of fractions of a second (ms/µs/ns). Example: In %t[dd-HH:mm:ss:ms], ms is specified with three digits for the milliseconds. A zero is prepended to the two-digit ms number.If a two-digit output is desired (like before V3.5 SP17), then a special compiler define has to be set in the compiler properties of the application: VISU_MILLISEC_NOLEADING_ZERO.

Recommended data types for date and time definitions: DATE, DATE_AND_TIME, DT, LDATE, LDATE_AND_TIME, LDT, LTOD, TIME_OF_DAY, TOD

By default, the names of the days and months are displayed in English. When localized texts are used, the System text list has to be supplemented. This text list is automatically created in the POUs view when the %t placeholder is used. The English terms have to be used as the IDs here. The localization can be done for both the abbreviated names and full names.

The format string for a date and time definition has the following format:

%t[ <date and time unit> ]

Syntax

Example

Description

Example in Visualization

<date and time unit>

Required

Identification for date and time units

Filters from the time value (data type: date and time) the value for the specified unit (year, month, day, hour, minute, milliseconds)

For 64-bit date and time values, also microseconds and nanoseconds

yyyy

%t[yyyy]

Year with century

Code: dateBy : DATE := DATE#2020-1-1;

Text property: By the year %t[yyyy]

Text variable property: PLC_PRG.dateBy

Output: By the year 2020

yy

%t[yy]

Year without century (00–99)

Code: dateSince : DATE := DATE#2000-1-1;

Text property: Since: %t[yy]

Text variable property: PLC_PRG.dateSince

Output: Since: 00

y

%t[y]

Year without century (0–99)

Code: dateSince : DATE := DATE#2000-1-1;

Text property: Since: %t[y]

Text variable property: PLC_PRG.dateSince

Output: Since: 0

MMMM

%t[MMMM]

Month as full name

Code: dateMonth : DATE := DATE#2016-1-1;

Text property: Month: %t[MMMM]

Text variable property: PLC_PRG.dateMonth

Output: Month: January

MMM

%t[MMM]

Month as abbreviated name

Code: dateMonth : DATE := DATE#2016-1-1;

Text property: Month: %t[MMM]

Text variable property: PLC_PRG.dateMonth

Output: Month: Jan

MM

%t[MM]

Month as number (01–12)

Code: dateMonth : DATE := DATE#2016-1-1;

Text property: Month: %t[MM]

Text variable property: PLC_PRG.dateMonth

Output: Month: 01

M

%t[M]

Month as number (1–12)

Code: dateMonth : DATE := DATE#2016-1-1;

Text property: Month: %t[M]

Text variable property: PLC_PRG.dateMonth

Output: Month: 1

ddddd

%t[ddddd]

Day of week as number (1 = Monday – 7 = Sunday)

Code: iDay : INT := 7;

Text property: Day: %t[ddddd]

Text variable property: PLC_PRG.iDay

Output: Day: 7

dddd

%t[dddd]

Day of week as full name

Code: iDay : INT := 7;

Text property: Day: %t[dddd]

Text variable property: PLC_PRG.iDay

Output: Day: Sunday

ddd

%t[ddd]

Day of week as abbreviated name

Code: iDay : INT := 7;

Text property: Day: %t[ddd]

Text variable property: PLC_PRG.iDay

Output: Day: Sun

dd

%t[dd]

Day of month as number (01–31)

Code: iDay : INT := 1;

Text property: Day: %t[dd]

Text variable property: PLC_PRG.iDay

Output: Day: 01

d

%t[d]

Day of month as number (1–31)

Code: iDay : INT := 1;

Text property: Day: %t[d]

Text variable property: PLC_PRG.iDay

Output: Day: 1

yyyy

%t[yyyy]

Day of year as number (001–366)

Code: dateOfNoReturn : DATE := DATE#2016-09-01;

Text property: Day of no return: %t[yyyy]

Text variable property: PLC_PRG.dateOfNoReturn

Output: Day of no return: 245

HH

%t[HH]

Hour in 24-hour format (00–23)

Example

  • hh = 11: 11

  • hh = 12: 12

  • hh = 13: 13

  • hh = 23: 23

  • hh = 00: 24

  • hh = 01: 01

Code: todEnd : TOD := TIME_OF_DAY#17:0:0;

Text property: Ends at: %t[HH]:00

Text variable property: PLC_PRG.todEnd

Output: Ends at 17:00

hh

%t[hh]

Hour in 12-hour format (01–12)

Example

  • hh = 11: 11

  • hh = 12: 12

  • hh = 13: 01

  • hh = 23: 11

  • hh = 00: 12

  • hh = 01: 01

Code: todEnd : TOD := TIME_OF_DAY#17:0:0;

Text property: Ends at: %t[hh] o'clock

Text variable property: PLC_PRG.todEnd

Output: Ends at: 05 o'clock

t

%t[t]

Abbreviation A or P in 12-hour format

A for 00 <= hh <= 11

P for 12 <= hh <= 23

Example

  • hh = 11: 11 A

  • hh = 12: 12 P (midday)

  • hh = 13: 01 P

  • hh = 23:11 P

  • hh = 00: 12 A (midnight)

  • hh = 01: 01

Code: tClosed : TOD := TOD#17:17:17.17;

Text property: Closed at %t[hh:mm t]

Text variable property: PLC_PRG.tClosed

Output: Closed at 05:17 P

tt

%t[tt]

Abbreviation AM or PM in 12-hour format

AM for 00 <= hh <= 11

PM for 12 <= hh <= 23

Example

  • hh = 11: 11 AM

  • hh = 12: 12 PM (midday)

  • hh = 13: 01 PM

  • hh = 23: 11 PM

  • hh = 00: 12 AM (midnight)

  • hh = 01: 01 AM

Code: tClosed : TOD := TOD#17:17:17.17;

Text property: Closed at %t[hh:mm tt]

Text variable property: PLC_PRG.tClosed

Output: Closed at 05:17 PM

Inside the brackets, identifications for date and time units can occur any number of times and can be interchanged with any strings.

Syntax

Example

Description

Example in Visualization

%t[yyyy-MM-dd dddd]

Date and day of the week with separators in between

Code: dateSet : DATE := DATE#2021-02-12;

Text property: Date: %t[yyyy-MM-dd dddd]

Text variable property: PLC_PRG.dateSet

Output: Date: 2/12/2021 Friday

%t[HH:mm:ss:ms]

Time of day

Code: dwTime : DWORD := 4294967295;

Text property: Time: %t[HH:mm:ss:ms]

Text variable property: PLC_PRG.dwTime

Output: Time: 23:59:59:999

%t[HH 'h' mm 'm'ss 's' ms 'ms']

If strings should be output which correspond to a format definition, then these have to be represented in single straight quotation marks.

Text property: %t['Time' HH 'h' mm 'm'ss 's' ms 'ms']

Output: Time: 23 h 59 m 59 s 999 ms

Text

Recommended data types of the placeholder variable: STRING, WSTRING

The format definition for strings and strings have the following format:

% <type>

Syntax

Example

Description

Example in Visualization

<type>

c

%c

Output of single character in ASCII character set

Code: byteChar : BYTE := 16#41;

Text property: Key: %c

Text variable property: PLC_PRG.byteChar

Output: Key: A

s

%s

Output of string

Recommended data types: STRING | WSTRING

Code: strName : STRING := 'Paul Smith';

Text property: Name: %s

Text variable property: PLC_PRG.strName

Output: Name: Paul Smith

When UTF-8 encoding is enabled for the STRING data type, language-specific characters are allowed for both the input and the output. Examples of language-specific characters include diacritic characters and Chinese characters.

For more information, see: Dialog: Project Settings – Compile options

Percent sign

Format definition for output of a percent sign

Syntax

Example

Description

Example in Visualization

&

%d%%

Output of the percent sign

With a placeholder variable:

Code: iPercentage : INT := 80;

Text property: Valid until %d%%.

Text variable property: PLC_PRG.iPercentage := 80;

Output: Valid until 80%

Text property: Valid until 90%%

Output: Valid until 90%